package com.web.dao;

import com.web.entity.Notice;
import org.apache.ibatis.annotations.*;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public interface NoticeMapper {
    @Delete({
        "delete from APP_NOTICE",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into APP_NOTICE (title, content, ",
        "type, sender, from_name, ",
        "target, target_name, ",
        "create_time, modify_time)",
        "values (#{title,jdbcType=VARCHAR}, #{content,jdbcType=VARCHAR}, ",
        "#{type,jdbcType=INTEGER}, #{sender,jdbcType=INTEGER}, #{fromName,jdbcType=VARCHAR}, ",
        "#{target,jdbcType=INTEGER}, #{targetName,jdbcType=VARCHAR}, ",
        "#{createTime,jdbcType=TIMESTAMP}, #{modifyTime,jdbcType=TIMESTAMP})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Integer.class)
    int insert(Notice record);

    int insertSelective(Notice record);

    @Select({
        "select",
        "id, title, content, type, sender, from_name, target, target_name, create_time, ",
        "modify_time",
        "from APP_NOTICE",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @ResultMap("BaseResultMap")
    Notice selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(Notice record);

    @Update({
        "update APP_NOTICE",
        "set title = #{title,jdbcType=VARCHAR},",
          "content = #{content,jdbcType=VARCHAR},",
          "type = #{type,jdbcType=INTEGER},",
          "sender = #{sender,jdbcType=INTEGER},",
          "from_name = #{fromName,jdbcType=VARCHAR},",
          "target = #{target,jdbcType=INTEGER},",
          "target_name = #{targetName,jdbcType=VARCHAR},",
          "create_time = #{createTime,jdbcType=TIMESTAMP},",
          "modify_time = #{modifyTime,jdbcType=TIMESTAMP}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Notice record);

    /**
     * 查询消息列表
     * @param type
     * @param userId
     * @return
     */
    List<Notice> listNotice(@Param("type") Integer type, @Param("userId") String userId);

    /**
     * 未读消息数
     * @param notice
     * @return
     */
    int unReadNum(Notice notice);

    /**
     * 查询是否有重复应聘
     * @param sender
     * @param contentId
     * @return
     */
    Notice searchIsRepeatRecruit(@Param("sender") String sender, @Param("contentId") Integer contentId);

    /**
     * 查询是否有重复求职
     * @param sender
     * @param contentId
     * @return
     */
    Notice searchIsRepeatJobApply(@Param("sender") String sender, @Param("contentId") Integer contentId);
}